<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="java.util.List"%>
<%@ page
	import="com.google.appengine.api.datastore.DatastoreServiceFactory"%>
<%@ page import="com.google.appengine.api.datastore.DatastoreService"%>
<%@ page import="com.google.appengine.api.datastore.Query"%>
<%@ page import="com.google.appengine.api.datastore.Entity"%>
<%@ page import="com.google.appengine.api.datastore.FetchOptions"%>
<%@ page import="com.google.appengine.api.datastore.Key"%>
<%@ page import="com.google.appengine.api.datastore.KeyFactory"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<html>
<head>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
</head>

<body>
<h2>Quiz Questions and Answers</h2>
<table class="table1">
	<tr>
		<th>Chinese</th> 				
		<th>Instruction</th> 				
		<th>Question</th> 				
		<th>a</th> 				
		<th>b</th> 				
		<th>c</th> 				
		<th>d</th> 				
		<th>correct</th> 				
	</tr>  	    	    
	<%
	
	pageContext.setAttribute("email", pageContext.getAttribute("email"));
   
	// Get the data
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

    
    Query query = new Query("Quiz");
	List<Entity> questions = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(20));

	
	for(Entity question : questions)
	{
		Key key = question.getKey();

	    System.err.println("KEY  " + key.toString());
	
   			pageContext.setAttribute("chinese", question.getProperty("chinese"));
   			pageContext.setAttribute("instruction", question.getProperty("instruction"));
   			pageContext.setAttribute("question", question.getProperty("question"));
   			pageContext.setAttribute("a", question.getProperty("a"));
   			pageContext.setAttribute("b", question.getProperty("b"));
   			pageContext.setAttribute("c", question.getProperty("c"));
   			pageContext.setAttribute("d", question.getProperty("d"));
   			pageContext.setAttribute("correct", question.getProperty("correct"));
		%>
		<tr>
		<td>
			${fn:escapeXml(chinese)}		
		</td> 				
							
		<td>
			${fn:escapeXml(instruction)}		
		</td> 				
							
		<td>
			${fn:escapeXml(question)}		
		</td> 				
							
		<td>
			${fn:escapeXml(a)}		
		</td>
		 
		<td>
			${fn:escapeXml(b)}		
		</td>
		 
		<td>
			${fn:escapeXml(c)}		
		</td>
		 
		<td>
			${fn:escapeXml(d)}		
		</td>
		 
		<td>
			${fn:escapeXml(correct)}		
		</td>
		 
		</tr>				
												
    	<%
    } //for
    
    %>
    
</table>  


</body>
</html>